home *** CD-ROM | disk | FTP | other *** search
/ PC for Alla 2005 May / PC för Alla 0505.iso / fullversioner / realsoft3d / data1.cab / Scripting / scripts / js / myclasses / toolbars / myvsl.js < prev   
Encoding:
Text File  |  2005-04-04  |  5.9 KB  |  215 lines

  1.  
  2. //
  3. // Description:
  4. //     Tool Bar example demonstrating now to derive new toolbar classes from
  5. //      'toolbar.js' base class. Defines new class called myVslTools. 
  6. //
  7. // Super class:
  8. //      myclasses/toolbars/toolbar.js
  9. //
  10. // Constructor:
  11. //      toolbar = new myVslTools(Integer Orientation);
  12. //
  13. // Attributes:
  14. //      --
  15. //
  16. // Methods:
  17. //      --
  18. //
  19.  
  20. include("myclasses/toolbars/mytoolbar.js"); // our super class
  21. include("real/layer/r3matlay.js");  // material layer
  22. include("real/code/r3vsl.js");      // vsl material
  23. include("real/code/r3mpphas.js");   // vsl shader 
  24. include("real/code/r3mptext.js");   // vsl texture map
  25. include("real/code/r3mpnois.js");   // vsl noise 
  26. include("real/code/r3mpcurv.js");   // vsl curve
  27. include("real/code/r3curve.js");    // curve object
  28. include("real/code/r3mpvar.js")     // variable
  29. include("real/code/r3mpif.js");     // if 
  30.  
  31. function myVsl(button, event, value)
  32. {
  33.     vsl = new r3Vsl(R3RA_Name, "my VSL");
  34.     if(vsl) {
  35.         button.layer.LOCKEXCLUSIVE(0);
  36.         button.layer.INSERT(0, 0, vsl);
  37.         button.layer.RELEASE(0);
  38.     }
  39. }
  40.  
  41. // create texture map VSL material
  42.  
  43. function myTextureMap(button, event, value)
  44. {
  45.     vsl = new r3Vsl(0);
  46.     vsl.SetName("texture map");
  47.     if(vsl) {
  48.         shader = new r3Mpphaselevel(0);
  49.         if(shader) {
  50.             shader.SetPhase(R3CLID_PHASESURFACE);
  51.             vsl.INSERTPROP(0, 0, shader);
  52.             texture = new r3Mptexture(0);
  53.             if(texture) {
  54.                 texture.SetParent(shader);
  55.                 texture.SetImageName("textures/lake.ppm");
  56.                 texture.SetTileX(TRUE);
  57.                 texture.SetTileY(TRUE);
  58.             }
  59.         }
  60.         button.layer.LOCKEXCLUSIVE(0);
  61.         button.layer.INSERT(0, 0, vsl);
  62.         button.layer.RELEASE(0);
  63.     }
  64. }
  65.  
  66.  
  67. // Create reflection map material
  68.  
  69. function myReflectionMap(button, event, value)
  70. {
  71.     vsl = new r3Vsl(0);
  72.     vsl.SetName("reflection map");
  73.  
  74.     if(vsl) {
  75.         shader = new r3Mpphaselevel(0);
  76.  
  77.         if(shader) {
  78.             shader.SetPhase(R3CLID_PHASESURFACE);
  79.             vsl.INSERTPROP(0, 0, shader);
  80.             texture = new r3Mptexture(0);
  81.             if(texture) {
  82.                 texture.SetParent(shader);
  83.                 texture.SetImageName("textures/lake.ppm");
  84.                 texture.SetOutputChannel(R3CLID_REFLECTIONCHANNEL);
  85.         texture.SetOutputName("Reflection");
  86.             }
  87.         }
  88.         button.layer.LOCKEXCLUSIVE(0);
  89.         button.layer.INSERT(0, 0, vsl);
  90.         button.layer.RELEASE(0);
  91.     }
  92. }
  93.  
  94.  
  95. // create noise material
  96.  
  97. function myNoise(button, event, value)
  98. {
  99.     vsl = new r3Vsl(0);
  100.     if(vsl) {
  101.         vsl.SetName("noise");
  102.         shader = new r3Mpphaselevel(0);
  103.         if(shader) {
  104.             shader.SetPhase(R3CLID_PHASESURFACE);
  105.             vsl.INSERTPROP(0, 0, shader);
  106.  
  107.             noise = new r3Mpnoise(0);
  108.             if(noise) {
  109.                 noise.SetParent(shader);
  110.                 noise.SetDimensions(3.0);
  111.                 noise.SetOctaves(4);
  112.                 noise.SetAmplitude(0.5);
  113.                 noise.SetBase(0.5);
  114.                 noise.SetSmooth(TRUE);
  115.             }
  116.         }
  117.         button.layer.LOCKEXCLUSIVE(0);
  118.         button.layer.INSERT(0, 0, vsl);
  119.         button.layer.RELEASE(0);
  120.     }
  121. }
  122.  
  123. // create a curve vsl object to define reflection
  124.  
  125. function myCurve(button, event, value)
  126. {
  127.     vsl = new r3Vsl(0);
  128.     if(vsl) {
  129.         vsl.SetName("curve");
  130.         shader = new r3Mpphaselevel(0);
  131.         if(shader) {
  132.             shader.SetPhase(R3CLID_PHASESURFACE);
  133.             vsl.INSERTPROP(0, 0, shader);
  134.  
  135.             mpcurve = new r3Mpcurve(0);
  136.             if(mpcurve) {
  137.                 mpcurve.SetParent(shader);
  138.  
  139.                 // attach to reflection channel 
  140.                 mpcurve.SetOutputChannel(R3CLID_REFLECTIONCHANNEL);
  141.         mpcurve.SetOutputName("Reflection");
  142.  
  143.         // fetch the actual curve object and insert a point to it
  144.                 curve = mpcurve.GetCurve();
  145.                 if(curve) {
  146.                     curve.ADDPOINTIFNOTONLINE(R3TID_VECTOR, new r3Vect(0.5, 0.5, 0.5), new r3Vect(0.3, 0.2, 0.1));
  147.                 }
  148.             }
  149.         }
  150.         button.layer.LOCKEXCLUSIVE(0);
  151.         button.layer.INSERT(0, 0, vsl);
  152.         button.layer.RELEASE(0);
  153.     }
  154. }
  155.  
  156.  
  157. function myIf(button, event, value)
  158. {
  159.     vsl = new r3Vsl(0);
  160.     if(vsl) {
  161.         vsl.SetName("If");
  162.         shader = new r3Mpphaselevel(0);
  163.         if(shader) {
  164.             shader.SetPhase(R3CLID_PHASESURFACE);
  165.             vsl.INSERTPROP(0, 0, shader);
  166.  
  167.             mpif = new r3Mpif(0);
  168.             if(mpif) {
  169.                 mpif.SetParent(shader);
  170.                 mpif.SetType(R3MPTYPE_IF);
  171.  
  172.                 mpif.SetCondition1(R3MPIFSTATE_TEST);
  173.                 mpif.SetMin1(0.3);
  174.                 mpif.SetMax1(0.7);
  175.  
  176.                 mpif.SetCondition2(R3MPIFSTATE_TEST);
  177.                 mpif.SetMin2(0.15);
  178.                 mpif.SetMax2(0.85);
  179.  
  180.                 mpif.SetCondition3(R3MPIFSTATE_OFF);
  181.                 mpif.SetMin3(0);
  182.                 mpif.SetMax3(0);
  183.             }
  184.         }
  185.         button.layer.LOCKEXCLUSIVE(0);
  186.         button.layer.INSERT(0, 0, vsl);
  187.         button.layer.RELEASE(0);
  188.     }
  189. }
  190.  
  191.  
  192. function myVslTools(orientation)
  193. {
  194.     if(arguments.length == 0)
  195.         return;
  196.  
  197.     // initialize interface to material layer
  198.     matLayer = new r3Materiallayer();
  199.     matLayer.r3Attach(Get("CurrentProject.Materials"));
  200.  
  201.     // call the super class constructor 
  202.     this.base = myToolBar; 
  203.     this.base("VSL Tools", orientation, matLayer);
  204.  
  205.     // add tool buttons 
  206.     this.AddTool("Material", myVsl);
  207.     this.AddTool("Texture",  myTextureMap);
  208.     this.AddTool("Noise",    myNoise);
  209.     this.AddTool("Reflection",    myReflectionMap);
  210.     this.AddTool("Curve",    myCurve);
  211.     this.AddTool("IF",    myIf);
  212. }
  213.  
  214. myVslTools.prototype=new myToolBar;
  215.